package no.ntnu.fp.gui.dialog;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import no.ntnu.fp.model.MeetingRoom;
import no.ntnu.fp.utils.MeetingRoomSchedule;
import no.ntnu.fp.utils.TimeInterval;

/**
 * @author H�kon Heggedal
 * 
 */
@SuppressWarnings("serial")
public class MeetingRoomRenderer extends JLabel implements ListCellRenderer{
	private MeetingRoomSchedule meetingRoomSchedule;
	private TimeInterval interval;
	private final Color ledigFarge = new Color(127,255,127); // lysegr�nn
	private final Color opptattFarge = new Color(255,127,127); // lyser�d

	public MeetingRoomRenderer() {
		setOpaque(true);
	}

	@Override
	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {
		if (meetingRoomSchedule != null) {
			MeetingRoom room = (MeetingRoom) value;
			if(room != null){
				boolean isAvailable = meetingRoomSchedule.isAvailable(room, interval);
				setBackground(  (isAvailable)? ledigFarge : opptattFarge);
				String roomStatus =	(isAvailable) ? "Ledig" : "Opptatt";
				if(isSelected){
					setBackground(list.getSelectionBackground());
					setForeground(list.getSelectionForeground());
				}
				setText(room.getName() + " " + roomStatus + " " + room.getCapacity());
			}
		}
		return this;
	}

	public void setMeetingRoomSchedule(MeetingRoomSchedule meetingRoomSchedule, TimeInterval interval) {
		this.meetingRoomSchedule = meetingRoomSchedule;
		this.interval = interval;
	}
	
	public void setMeetingRoomInterval(TimeInterval interval){
		this.interval = interval;
	}

}
